package com.qidian.mes.wm.controller;

import com.alibaba.fastjson2.JSON;
import com.qidian.check.util.annotation.CheckParam;
import com.qidian.mes.wm.dto.WareAreaDTO;
import com.qidian.mes.wm.dto.WareAreaSetDTO;
import com.qidian.mes.wm.service.WareAreaService;
import com.qidian.mes.wm.service.WareAreaSetService;
import com.qidian.mes.wm.service.WareService;
import com.qidian.mes.util.pojo.QdResult;
import com.qidian.mes.wm.dto.WareDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 小可怎么都睡不够
 * @Description:
 * @Time: 2024-04-13 09:46
 **/
@RestController
@RequestMapping("/ware")
@CrossOrigin
public class WareController {
    @Autowired
    WareService wareService;
    @Autowired
    WareAreaService wareAreaService;
    @Autowired
    WareAreaSetService wareAreaSetService;

    @GetMapping("/query")
public QdResult getWareById(
             @RequestParam(defaultValue = "") @CheckParam(required = true,allowedValues = {"男","女"}) String wareName,
             @RequestParam(defaultValue = "1") Integer page,
             @RequestParam(defaultValue = "10") Integer limit) {
        return wareService.getWareById(wareName,page,limit);
    }

    @DeleteMapping("/del/mall")
    public QdResult deleteWareByIds(@RequestBody Integer[] ids) {
        return wareService.deleteWareByIds(ids);
    }

    @PostMapping("/add")
    public QdResult addWare(@RequestBody WareDTO ware) {
        return wareService.addWare(ware);
    }

    @DeleteMapping("/del")
    public QdResult deleteWare(@RequestParam Integer wareId, @RequestParam Integer status) {
        return wareService.deleteWare(wareId, status);
    }
    @GetMapping("/count")
    public QdResult getWareCount(@RequestParam String wareName){
        return wareService.getWareCount(wareName);
    }


    @PutMapping("/update")
    public QdResult updateWare(@RequestBody String data) {
        WareDTO ware =  JSON.parseObject(data, WareDTO.class);

        return wareService.updateWare(ware);
    }










    //库区管理
    @GetMapping("/area/query")
    public QdResult getWareAreaById(@RequestParam Integer wareId,@RequestParam String wareAreaName,@RequestParam Integer page,@RequestParam Integer limit) {
        return wareAreaService.query(wareId,wareAreaName, page, limit);
    }

    @PostMapping("/area/add")
    public QdResult addAreaWare(@RequestBody WareAreaDTO ware) {
        return wareAreaService.add(ware);
    }

    @DeleteMapping("/area/del")
    public QdResult deleteAreaWare(@RequestParam Integer wareAreaId) {
        return wareAreaService.delete(wareAreaId);
    }
    @PutMapping("/area/update")
    public QdResult updateAreaWare(@RequestBody String data) {
        WareAreaDTO ware =  JSON.parseObject(data, WareAreaDTO.class);
        System.out.println(ware);
        return wareAreaService.update(ware);
    }
    @GetMapping("/area/count")
    public QdResult getCount(@RequestParam Integer wareId) {
        return wareAreaService.getCount(wareId);
    }









    //库位管理
    @GetMapping("/area/set/query")
    public QdResult getAreaSets(@RequestParam Integer wareAreaId) {
        return wareAreaSetService.getAreaSets(wareAreaId);
    }
    @PostMapping("/area/set/add")
    public QdResult addAreaSet(@RequestBody WareAreaSetDTO wareAreaSetDTO) {
        return wareAreaSetService.addAreaSet(wareAreaSetDTO);
    }
    @PutMapping("/area/set/update")
    public QdResult updateAreaSet(@RequestBody WareAreaSetDTO wareAreaSetDTO) {
        System.out.println(wareAreaSetDTO);
        return wareAreaSetService.updateAreaSet(wareAreaSetDTO);
    }
    @DeleteMapping("/area/set/del")
    public QdResult deleteAreaSet(@RequestBody WareAreaSetDTO wareAreaSetDTO) {
        return wareAreaSetService.deleteAreaSet(wareAreaSetDTO);
    }

}
